﻿using CPF;
using CPF.Controls;
using CPF.Input;
using CPF.Svg;

using EHO.AutoUpdate.Upgrade.VModel;

namespace EHO.AutoUpdate.Upgrade
{
    public class MainWindow : Window
    {
        protected override void InitializeComponent()
        {
            LoadStyleFile("res://EHO.AutoUpdate.Upgrade/css/mingliangmoshi.css");//加载样式文件，文件需要设置为内嵌资源
            Title = "更新程序";
            Width = 400;
            Height = 150;
            Background = null;
            Children.Add(new WindowFrame(this,
            new Panel
            {
                Width = "100%",
                Height = "100%",
                Children = //内容元素放这里
                {
                    new Panel
                    {
                        Name ="downloadinfo",
                        Width = "100%",
                        Height="100%",
                        Children=
                        {
                            new Grid
                            {
                               Width="100%",
                               Height="100%",
                               RowDefinitions=
                                {
                                    new RowDefinition(){ Height=50 },
                                    new RowDefinition(){ Height=50 },
                                    new RowDefinition(),
                                },
                               Children=
                                {
                                    new StackPanel
                                    {
                                        Orientation=Orientation.Horizontal,
                                        Width="100%",
                                        Height="100%",
                                        Attacheds=
                                            {
                                                {Grid.ColumnIndex,0 },
                                                {Grid.RowIndex,0 }
                                            },
                                        Children=
                                        {
                                            new TextBlock
                                            {
                                                 Width=50,
                                                 MarginLeft="10",
                                                 Text="正在下载",
                                            },
                                            new TextBlock
                                            {
                                                Width=50,
                                                MarginLeft="1",
                                                Bindings={ {nameof(TextBlock.Text),nameof(MainWindowVM.DownLoadRatio) } }
                                            },
                                            new TextBlock
                                            {
                                                Width=150,
                                                MarginLeft="1",
                                                Bindings={ {nameof(TextBlock.Text),nameof(MainWindowVM.Speed) } }
                                            }
                                        }
                                    },
                                    new StackPanel
                                    {
                                        Width="100%",
                                        Height="100%",
                                        Orientation=Orientation.Horizontal,
                                        Attacheds=
                                        {
                                            {Grid.RowIndex,1 }
                                        },
                                        Children=
                                        {
                                            new TextBlock
                                             {
                                                 Width=100,
                                                 MarginLeft="10",
                                                 Text="下载进度：",
                                             },
                                            new ProgressBar
                                            {
                                                Height=20,
                                                Width=270,
                                                Bindings={ {nameof(ProgressBar.Value),nameof(MainWindowVM.DownLoadProcess) } }
                                            }
                                        }
                                    }

                                }
                            }
                        }
                    }
                }
            }));
            //_UpgradeService.Run();
            if (!DesignMode)//设计模式下不执行，也可以用#if !DesignMode
            {

            }
        }
    }
}
